/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.VipConsume;
import com.sasis.dao.VipConsumeDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class VipConsumeDaoiBatis extends BaseDaoiBATIS implements VipConsumeDao {

    /**
     * @see com.sasis.dao.VipConsumeDao#getVipConsumes(com.sasis.model.VipConsume)
     */
    public List getVipConsumes(final VipConsume vipConsume) {
          return getSqlMapClientTemplate().queryForList("getVipConsumes", vipConsume);
    }

    /**
     * @see com.sasis.dao.VipConsumeDao#getVipConsume(Integer id)
     */
    public VipConsume getVipConsume(Integer id) {
        VipConsume vipConsume = (VipConsume) getSqlMapClientTemplate().queryForObject("getVipConsume", id);

        if (vipConsume == null) {
            throw new ObjectRetrievalFailureException(VipConsume.class, id);
        }

        return vipConsume;
    }

    /**
     * @see com.sasis.dao.VipConsumeDao#saveVipConsume(VipConsume vipConsume)
     */    
    public void saveVipConsume(final VipConsume vipConsume) {
        Integer id = vipConsume.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addVipConsume", vipConsume);
        } else {
            getSqlMapClientTemplate().update("updateVipConsume", vipConsume);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(VipConsume.class, id);
        }
    }

    /**
     * @see com.sasis.dao.VipConsumeDao#removeVipConsume(Integer id)
     */
    public void removeVipConsume(VipConsume vipConsume) {
        getSqlMapClientTemplate().update("deleteVipConsume",  vipConsume);
    }
}
